import { Subject } from "rxjs";
import { V3proSubjectMessage } from "../model/v3pro.model";
import { HealthCheckTask } from "./health.check.class";
import { curry } from "ramda";
import { HealthCheckServer } from "./health.check.server";
import { V3proCheckSendboxCommTask } from "./v3pro.check.sendbox.comm.task";
import { V3proCheckTemperatureTask } from "./v3pro.check.temperature.task";
import { V3proCheckStartTimeTask } from "./v3pro.check.start.time.task";
import { V3proCheckLumSensorTask } from "./v3pro.check.lum.sensor.task";
import { V3proCheckDeadPixelTask } from "./v3pro.check.dead.pixel.task";
import { V3proCheckDeadPixelTriggerTask } from "./v3pro.check.dead.pixel.trigger.task";

/**
 * 健康检查任务列表
 */
const HealthCheckTasks = new Set<new () => HealthCheckTask>([
  V3proCheckDeadPixelTask,
  V3proCheckLumSensorTask,
  V3proCheckDeadPixelTriggerTask,
  // V3proCheckPanelCommTask,
  // V3proCheckPanelSignalTask,
  // V3proCheckPanelTemperatureTask,
  // V3proCheckPanelVoltageTask,
  // V3proCheckScanboardCommTask,
  // V3proCheckScanboardErrorResetTask,
  // V3proCheckScanboardNetworkErrorBitTask,
  // V3proCheckScanboardTemperatureTask,
  // V3proCheckScanboardVoltageTask,
  // V3proCheckSignalInputTask,
  V3proCheckSendboxCommTask,
  // V3proCheckSendboxTemperatureTask,
  // V3proCheckSendboxNetworkLinkTask,
  V3proCheckTemperatureTask,
  V3proCheckStartTimeTask,
]);

/**
 * 添加观察者
 */
const addObservable = curry(
  <T extends HealthCheckTask>(observable: Subject<V3proSubjectMessage>, task: new () => T) => {
    return new HealthCheckServer(task, observable);
  },
) as (
  observable: Subject<V3proSubjectMessage>,
) => <T extends HealthCheckTask>(task: new () => T) => T;

/**
 * 生成健康检查任务列表
 * @param subject 观察者
 */
export const genHealthCheckTasks = (subject: Subject<V3proSubjectMessage>): HealthCheckTask[] => {
  const addObservableHandler = addObservable(subject);
  return [...HealthCheckTasks].map(addObservableHandler);
};
